In [6]:
import numpy as np
In [7]:
ones_arr = np.ones((3,3))
In [8]:
ones_arr
Out[8]:
array([[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]])
In [9]:
ones_arr = np.ones((5,5),dtype=int)
In [10]:
ones_arr
Out[10]:
array([[1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1]])
In [11]:
zeros_arr = np.zeros((3,3),dtype = int)
In [12]:
zeros_arr
Out[12]:
array([[0, 0, 0],
       [0, 0, 0],
       [0, 0, 0]])
In [13]:
ones_arr
Out[13]:
array([[1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1]])
In [14]:
ones_arr*255
Out[14]:
array([[255, 255, 255, 255, 255],
       [255, 255, 255, 255, 255],
       [255, 255, 255, 255, 255],
       [255, 255, 255, 255, 255],
       [255, 255, 255, 255, 255]])
In [15]:
zeros_arr
Out[15]:
array([[0, 0, 0],
       [0, 0, 0],
       [0, 0, 0]])
In [16]:
ones_arr
Out[16]:
array([[1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1]])
In [17]:
import matplotlib.pyplot as plt
In [18]:
%matplotlib inline
In [19]:
from PIL import Image  # python imaging library
In [20]:
#flower_img = Image.open('C:\Users\Rachana Jena\Downloads\flower.jpeg'))
In [21]:
flower_img = Image.open(r'C:\Users\Rachana Jena\OneDrive\Pictures\flower.jpeg')
In [22]:
flower_img
Out[22]:
No description has been provided for this image
In [23]:
#my_img = Image.open(r'C:\Users\Rachana Jena\OneDrive\Pictures\flower.jpeg')
In [24]:
#my_img
In [25]:
type(flower_img)
Out[25]:
PIL.JpegImagePlugin.JpegImageFile
In [26]:
flower_arr = np.asarray(flower_img)
flower_arr
Out[26]:
array([[[ 1,  1,  1],
        [ 1,  1,  1],
        [ 1,  1,  1],
        ...,
        [ 0,  0,  0],
        [ 0,  0,  0],
        [ 0,  0,  0]],

       [[ 1,  1,  1],
        [ 1,  1,  1],
        [ 1,  1,  1],
        ...,
        [ 0,  0,  0],
        [ 0,  0,  0],
        [ 0,  0,  0]],

       [[ 1,  1,  1],
        [ 1,  1,  1],
        [ 1,  1,  1],
        ...,
        [ 0,  0,  0],
        [ 0,  0,  0],
        [ 0,  0,  0]],

       ...,

       [[69, 76, 68],
        [62, 69, 61],
        [47, 54, 46],
        ...,
        [61, 59, 60],
        [70, 68, 69],
        [73, 71, 72]],

       [[71, 78, 70],
        [64, 71, 63],
        [48, 55, 47],
        ...,
        [61, 59, 60],
        [70, 68, 69],
        [73, 71, 72]],

       [[73, 80, 72],
        [65, 72, 64],
        [49, 56, 48],
        ...,
        [60, 58, 59],
        [69, 67, 68],
        [73, 71, 72]]], dtype=uint8)
In [27]:
type(flower_arr)
Out[27]:
numpy.ndarray
In [28]:
flower_arr.shape
Out[28]:
(900, 1440, 3)
In [29]:
plt.imshow(flower_arr)
Out[29]:
<matplotlib.image.AxesImage at 0x29502f65a30>
No description has been provided for this image
In [30]:
flower_red = flower_arr.copy()
In [31]:
flower_red
Out[31]:
array([[[ 1,  1,  1],
        [ 1,  1,  1],
        [ 1,  1,  1],
        ...,
        [ 0,  0,  0],
        [ 0,  0,  0],
        [ 0,  0,  0]],

       [[ 1,  1,  1],
        [ 1,  1,  1],
        [ 1,  1,  1],
        ...,
        [ 0,  0,  0],
        [ 0,  0,  0],
        [ 0,  0,  0]],

       [[ 1,  1,  1],
        [ 1,  1,  1],
        [ 1,  1,  1],
        ...,
        [ 0,  0,  0],
        [ 0,  0,  0],
        [ 0,  0,  0]],

       ...,

       [[69, 76, 68],
        [62, 69, 61],
        [47, 54, 46],
        ...,
        [61, 59, 60],
        [70, 68, 69],
        [73, 71, 72]],

       [[71, 78, 70],
        [64, 71, 63],
        [48, 55, 47],
        ...,
        [61, 59, 60],
        [70, 68, 69],
        [73, 71, 72]],

       [[73, 80, 72],
        [65, 72, 64],
        [49, 56, 48],
        ...,
        [60, 58, 59],
        [69, 67, 68],
        [73, 71, 72]]], dtype=uint8)
In [32]:
flower_arr == flower_red
Out[32]:
array([[[ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True],
        ...,
        [ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True]],

       [[ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True],
        ...,
        [ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True]],

       [[ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True],
        ...,
        [ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True]],

       ...,

       [[ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True],
        ...,
        [ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True]],

       [[ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True],
        ...,
        [ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True]],

       [[ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True],
        ...,
        [ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True]]])
In [33]:
plt.imshow(flower_red)
Out[33]:
<matplotlib.image.AxesImage at 0x29503061190>
No description has been provided for this image
In [34]:
flower_red.shape
Out[34]:
(900, 1440, 3)
In [35]:
# R G B

plt.imshow(flower_red[:,:,0])
Out[35]:
<matplotlib.image.AxesImage at 0x29503027950>
No description has been provided for this image
In [36]:
flower_red[:,:,0]
Out[36]:
array([[ 1,  1,  1, ...,  0,  0,  0],
       [ 1,  1,  1, ...,  0,  0,  0],
       [ 1,  1,  1, ...,  0,  0,  0],
       ...,
       [69, 62, 47, ..., 61, 70, 73],
       [71, 64, 48, ..., 61, 70, 73],
       [73, 65, 49, ..., 60, 69, 73]], dtype=uint8)
In [37]:
plt.imshow(flower_red[:,:,0], cmap='Greys')
Out[37]:
<matplotlib.image.AxesImage at 0x29504ef3800>
No description has been provided for this image
In [38]:
plt.imshow(flower_red[:,:,1], cmap='grey')
Out[38]:
<matplotlib.image.AxesImage at 0x29504f4f230>
No description has been provided for this image
In [39]:
plt.imshow(flower_red[:,:,2], cmap='grey')
Out[39]:
<matplotlib.image.AxesImage at 0x29504ef31a0>
No description has been provided for this image
In [40]:
flower_red[:,:,0]
Out[40]:
array([[ 1,  1,  1, ...,  0,  0,  0],
       [ 1,  1,  1, ...,  0,  0,  0],
       [ 1,  1,  1, ...,  0,  0,  0],
       ...,
       [69, 62, 47, ..., 61, 70, 73],
       [71, 64, 48, ..., 61, 70, 73],
       [73, 65, 49, ..., 60, 69, 73]], dtype=uint8)
In [41]:
flower_red[:,:,1]
Out[41]:
array([[ 1,  1,  1, ...,  0,  0,  0],
       [ 1,  1,  1, ...,  0,  0,  0],
       [ 1,  1,  1, ...,  0,  0,  0],
       ...,
       [76, 69, 54, ..., 59, 68, 71],
       [78, 71, 55, ..., 59, 68, 71],
       [80, 72, 56, ..., 58, 67, 71]], dtype=uint8)
In [42]:
flower_red[:,:,2]
Out[42]:
array([[ 1,  1,  1, ...,  0,  0,  0],
       [ 1,  1,  1, ...,  0,  0,  0],
       [ 1,  1,  1, ...,  0,  0,  0],
       ...,
       [68, 61, 46, ..., 60, 69, 72],
       [70, 63, 47, ..., 60, 69, 72],
       [72, 64, 48, ..., 59, 68, 72]], dtype=uint8)
In [43]:
flower_red[:,:,1] = 0
In [44]:
flower_red[:,:,1]
Out[44]:
array([[0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       ...,
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0]], dtype=uint8)
In [45]:
plt.imshow(flower_red)
Out[45]:
<matplotlib.image.AxesImage at 0x295065f3ad0>
No description has been provided for this image
In [46]:
flower_red[:,:,2]
Out[46]:
array([[ 1,  1,  1, ...,  0,  0,  0],
       [ 1,  1,  1, ...,  0,  0,  0],
       [ 1,  1,  1, ...,  0,  0,  0],
       ...,
       [68, 61, 46, ..., 60, 69, 72],
       [70, 63, 47, ..., 60, 69, 72],
       [72, 64, 48, ..., 59, 68, 72]], dtype=uint8)
In [47]:
flower_red[:,:,2] = 0
In [48]:
flower_red[:,:,2]
Out[48]:
array([[0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       ...,
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0]], dtype=uint8)
In [49]:
plt.imshow(flower_red)
Out[49]:
<matplotlib.image.AxesImage at 0x29506911190>
No description has been provided for this image
In [50]:
flower_arr
Out[50]:
array([[[ 1,  1,  1],
        [ 1,  1,  1],
        [ 1,  1,  1],
        ...,
        [ 0,  0,  0],
        [ 0,  0,  0],
        [ 0,  0,  0]],

       [[ 1,  1,  1],
        [ 1,  1,  1],
        [ 1,  1,  1],
        ...,
        [ 0,  0,  0],
        [ 0,  0,  0],
        [ 0,  0,  0]],

       [[ 1,  1,  1],
        [ 1,  1,  1],
        [ 1,  1,  1],
        ...,
        [ 0,  0,  0],
        [ 0,  0,  0],
        [ 0,  0,  0]],

       ...,

       [[69, 76, 68],
        [62, 69, 61],
        [47, 54, 46],
        ...,
        [61, 59, 60],
        [70, 68, 69],
        [73, 71, 72]],

       [[71, 78, 70],
        [64, 71, 63],
        [48, 55, 47],
        ...,
        [61, 59, 60],
        [70, 68, 69],
        [73, 71, 72]],

       [[73, 80, 72],
        [65, 72, 64],
        [49, 56, 48],
        ...,
        [60, 58, 59],
        [69, 67, 68],
        [73, 71, 72]]], dtype=uint8)
In [51]:
flower_red
Out[51]:
array([[[ 1,  0,  0],
        [ 1,  0,  0],
        [ 1,  0,  0],
        ...,
        [ 0,  0,  0],
        [ 0,  0,  0],
        [ 0,  0,  0]],

       [[ 1,  0,  0],
        [ 1,  0,  0],
        [ 1,  0,  0],
        ...,
        [ 0,  0,  0],
        [ 0,  0,  0],
        [ 0,  0,  0]],

       [[ 1,  0,  0],
        [ 1,  0,  0],
        [ 1,  0,  0],
        ...,
        [ 0,  0,  0],
        [ 0,  0,  0],
        [ 0,  0,  0]],

       ...,

       [[69,  0,  0],
        [62,  0,  0],
        [47,  0,  0],
        ...,
        [61,  0,  0],
        [70,  0,  0],
        [73,  0,  0]],

       [[71,  0,  0],
        [64,  0,  0],
        [48,  0,  0],
        ...,
        [61,  0,  0],
        [70,  0,  0],
        [73,  0,  0]],

       [[73,  0,  0],
        [65,  0,  0],
        [49,  0,  0],
        ...,
        [60,  0,  0],
        [69,  0,  0],
        [73,  0,  0]]], dtype=uint8)
In [52]:
flower_img
Out[52]:
No description has been provided for this image
In [53]:
arr1 = np.asarray(flower_img)
In [54]:
type(arr1)
Out[54]:
numpy.ndarray
In [55]:
arr1.shape
Out[55]:
(900, 1440, 3)
In [56]:
plt.imshow(arr1)
Out[56]:
<matplotlib.image.AxesImage at 0x29506961700>
No description has been provided for this image
In [73]:
flower_img1 = arr1.copy()
In [58]:
flower_img1[:,:,0] = 0
In [59]:
plt.imshow(flower_img1)
Out[59]:
<matplotlib.image.AxesImage at 0x29504efc290>
No description has been provided for this image
In [74]:
flower_img1[:,:,1]
Out[74]:
array([[ 1,  1,  1, ...,  0,  0,  0],
       [ 1,  1,  1, ...,  0,  0,  0],
       [ 1,  1,  1, ...,  0,  0,  0],
       ...,
       [76, 69, 54, ..., 59, 68, 71],
       [78, 71, 55, ..., 59, 68, 71],
       [80, 72, 56, ..., 58, 67, 71]], dtype=uint8)
In [87]:
flower_img1[:,:,1] = 0
In [75]:
import matplotlib.pyplot as plt
plt.imshow(flower_img1[:,:,1],cmap= 'PuBu')
Out[75]:
<matplotlib.image.AxesImage at 0x2950df95610>
No description has been provided for this image
In [77]:
plt.imshow(flower_img1[:,:,1],cmap='Oranges')
Out[77]:
<matplotlib.image.AxesImage at 0x2950e6f4e00>
No description has been provided for this image
In [79]:
plt.imshow(flower_img1[:,:,1],cmap='Purples')
Out[79]:
<matplotlib.image.AxesImage at 0x295101090d0>
No description has been provided for this image
In [80]:
plt.imshow(flower_img1[:,:,1],cmap='RdPu')
Out[80]:
<matplotlib.image.AxesImage at 0x29510121700>
No description has been provided for this image
In [82]:
plt.imshow(flower_img1[:,:,1],cmap='BuGn')
Out[82]:
<matplotlib.image.AxesImage at 0x29506769880>
No description has been provided for this image
In [83]:
plt.imshow(flower_img1[:,:,1],cmap='PuBuGn')
Out[83]:
<matplotlib.image.AxesImage at 0x29502f649b0>
No description has been provided for this image
In [84]:
plt.imshow(flower_img1[:,:,1],cmap='PuRd')
Out[84]:
<matplotlib.image.AxesImage at 0x295104531a0>
No description has been provided for this image
In [85]:
plt.imshow(flower_img1[:,:,1],cmap='OrRd')
Out[85]:
<matplotlib.image.AxesImage at 0x2950e71cb30>
No description has been provided for this image
In [86]:
plt.imshow(flower_img1[:,:,1],cmap='YlGnBu')
Out[86]:
<matplotlib.image.AxesImage at 0x29510a21970>
No description has been provided for this image
In [ ]: